<?php

class m_rights_actions_AjaxChangeDocRightsAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$groupId = $this->getRequestParameter("groupId");
		$module = $this->getRequestParameter("moduleRight");
		$docId = $this->getRequestParameter("docId");
        $docLang = $this->getRequestParameter("docLang");
		$rule = $this->getRequestParameter("rule");
        $blockId = $this->getRequestParameter("blockId");
        $result = array();

        $document = $this->getDocumentProvider()->getByUniqueId($docId, $docLang);
        if($module == "page" && $document->getDocumentModel() == "modules_website/page" && !is_null($blockId))
        {
            $rights = $document->setBlockRight($groupId, $blockId, $rule);
            $infos = array('documentId' => $document->getUniqueId(), 'documentLang' => $document->getLang(), 'module' => $module, 'group' => $groupId, 'blockId' => $blockId);
            $infos['rights'] = $rights;
            $result = array($infos);
        }
        elseif(is_null($blockId))
        {
            $rightsService = m_rights_services_RightsService::getInstance();
            $rightsService->saveRightsForDocument($groupId, $module, $document, $rule);
            $result = $rightsService->jsTab;
        }
        
        echo json_encode($result);
	}	
	
	public function validate()
	{
		return $this->userHasRight(array("backoffice_accessBo","rights_Edit"));
	}
}